﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;

public partial class WebUserControl_ControlTongKetLuongThuongThang : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    string str = BCDataCenter.Configuration.CurrentConnectionString;
    static string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                GetNextMonthToClosed();
            }
            catch (Exception ex)
            {
                BCDataCenter.ClassWriteLogErr obj = new BCDataCenter.ClassWriteLogErr();
                string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
                obj.ErrorLog(ex.Message, method);
            }
        }
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            dt = new ClassExecute.ClassExecute();
            DataTable db = dt.Get_Data_DataTable(str,ref error, "[ls_isAllSiteCloseLastDay]", CommandType.StoredProcedure);
            if (db.Rows.Count == 0)
            {
                bool kq = dt.ExecuteSQl_bool(str, CommandType.StoredProcedure, "[ls_closeMonth]", ref error,
                    new SqlParameter("@MmYyyy", txtThang.Text.Substring(0, 2).ToString() + txtThang.Text.Substring(3).ToString()));
                if (kq)
                {
                    uscMsgBox1.AddMessage("Hoàn thành khóa sổ tháng", uscMsgBox.enmMessageType.Success);
                    GridView1.DataSource = null;
                    GridView1.DataBind();
                }
            }
            else
            {
                GridView1.DataSource = db;
                GridView1.DataBind();
            }
        }
        catch (Exception ex)
        {
            BCDataCenter.ClassWriteLogErr obj = new BCDataCenter.ClassWriteLogErr();
            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            obj.ErrorLog(ex.Message, method);
        }
    }
    void GetNextMonthToClosed()
    {
        dt = new ClassExecute.ClassExecute();
        txtThang.Text = dt.GetDataDepend(str, "[ls_getNextMonthToClose]", CommandType.StoredProcedure,ref error);

    }
}
